
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
          name="viewport">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="format-detection" content="email=no">
    <link rel="stylesheet" href="../css/mobile-select-area.css">
    <link rel="stylesheet" href="../css/base.css">
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script src="../js/city.js"></script>
    <script src="../js/dialog.js"></script>
    <script src="../js/mobile-select-area.js"></script>
    <script src="../js/public.js"></script>
    <title>新增服务地址</title>
    <style>
        body{background: #f7f7f7;}
        #allmap{width:100%;height:3rem;}
        p{margin-left:5px; font-size:14px;}
        .sx{    border-right: 1px solid #333;
            height: .28rem;
            float: left;
            margin-top: .36rem;}
        .inputs{width: 70%;border: none;margin: .28rem 0;background: #f7f7f7;color: #333;font-size: 12px;}
        .textar{width: 70%;border: none;color: #333;padding:  .2rem;box-sizing: border-box;height: 1.5rem;background: #f7f7f7;margin-top: .1rem;font-size: 12px;}
        .h11{height: 1rem;line-height: 1rem;margin: 0 .3rem;border-bottom: 1px solid #eee;}
        .footer-btn-new-in{position: absolute;bottom: .8rem;left: .3rem;right: .3rem;background: #fa4535;font-size: 14px;color: #fff;text-align: center; line-height: .9rem;border-radius: .08rem;}
        .bort{border-bottom: solid 1px #eee;}
        .inpu-span{
            display: inline-block;
            padding-left: .2rem;
            box-sizing: border-box;
            width: 96%;
            height: .66rem;
        }
        .div-address{
            line-height: 1.1rem;
            border-bottom: solid 1px #eee;
            padding-right: .2rem;
            margin: 0 .3rem;
            font-size: 16px;
            color: #666666;
        }
        .fs{
            font-size: 12px;
        }
        .public-header{
            position: relative;
            text-align: center;
            box-sizing: border-box;
            background: #5F3104;
            color: #fff;
            line-height: 40px;

        }
        .footer-btn-new-ins{
            position: absolute;
            right: .2rem;
            line-height: 40px;
        }
    </style>
</head>
<body>
<div class="public-header">
    新增地址
    <span class="footer-btn-new-ins">保存</span>
</div>
<div class="h11 bort" style="position: relative;">
    <span class="fs">联系人</span>
    <input type="text" placeholder="输入联系人姓名" size="10" maxlength="10" class=" he44 f32 pl2 mt mb inputs " id="tel_name">
    <img src="../img/txl.png" alt="" style="width: .32rem;height: .32rem;position: absolute;right: 5px;top: .34rem;">
</div>
<div class="h11  bort">
    <span class="fs">手机号码</span>
    <input type="tel" placeholder="输入联系人手机号"  pattern="\d*" size="11" maxlength="11" class=" he44 f32 mt mb pl2 inputs" id="tel_intro">
</div>
<div class="h11  bort" style="position: relative;">
    <span class="fs">选择地区</span>
    <input type="tel" placeholder="请输入地区信息" size="11" maxlength="11" class=" he44 f32 mt mb pl2 inputs" id="txt_area">
    <img src="../img/dws.png" alt="" style="width: .32rem;height: .32rem;position: absolute;right: 5px;top: .34rem;">
</div>
<div class="h11  bort">
    <span class="fs">详细地址</span>
    <input type="text" placeholder="请输入接到门牌信息" size="30" maxlength="30" class=" he44 f32 mt mb pl2 inputs" id="txt_areaintro">
</div>
<div class="h11  bort">
    <span class="fs">邮政编码</span>
    <input type="tel" placeholder="输入邮政编码"  class=" he44 f32 mt mb pl2 inputs" id="postCode" maxlength="6">
</div>
<!--<div class="h11">
    <span class="sx"></span>
    <textarea id="txtintro" class="textar f32 bort" size="50" maxlength="50" style="-webkit-user-select: text;"   id="address_intro" cols="30" rows="10" placeholder="输入详细地址如:xx省xx市xx区7号楼2单元305"></textarea>
    &lt;!&ndash;<textarea id="address_intro" name=""  cols="30" rows="10"></textarea>&ndash;&gt;
</div>-->

<!--<div class="footer-btn-new-in" >
    保存
</div>-->

<script>
    var $name =  decodeURI(decodeURI( GetQueryString('name')));
    var $phone = GetQueryString('phone');
    var $address = decodeURI(decodeURI(GetQueryString('address')));
    var $code = GetQueryString('code');
    var _address = {};
    var id = GetQueryString('id');
        $(function (){
            if(!isNull(id)){
                $("#tel_name").val($name);
                $("#tel_intro").val($phone);
                var newaddress = $address.split("|");
                console.log(newaddress);
                $("#txt_area").val(newaddress[0]+newaddress[1]+newaddress[2]);
                _address.province = newaddress[0];
                _address.city = newaddress[1];
                _address.area = newaddress[2];
                $("#txt_areaintro").val(newaddress[3]);
                $("#postCode").val($code);
            }



        $(".footer-btn-new-ins").click(function (){
            if(isNull($("#tel_name").val())){
                alert("请填写正确的姓名");
                return false;
            }
            if(isNull($("#tel_intro").val())){
                alert("请填写正确的手机号");
                return false;
            }

            if(!(/^1[34578]\d{9}$/.test($("#tel_intro").val()))){
                alert("请填写正确的手机号码");
                return false;
            }


            if(isNull($("#postCode").val())){
                alert("请填写正确的邮政编码");
                return false;
            }
            if(isNull($("#txt_area").val())){
                alert("请填写省市区");
                return false;
            }
            if(isNull($("#txt_areaintro").val())){
                alert("请填写详细地址");
                return false;
            }
            var newUrl = "?uid="+sessionStorage.getItem("uid")+"&name="+$("#tel_name").val()+"&phone="+$("#tel_intro").val()+"&province="+_address.province+"&city="+_address.city+"&area="+_address.area+"&address="+$("#txt_areaintro").val()+"&postCode="+$("#postCode").val();
            if(isNull(id)){
                $.ajax({
                    url:base_url+"ZITAOHUI/user/addAddress"+newUrl,
                    success:function (data){
                        if(data.code == 1){
                            alert("保存成功");
                            window.location.replace('./personladdress-list.html');
                        }
                    }
                })
            }else{
                $.ajax({
                    url:base_url+"ZITAOHUI/user/updateAddress"+newUrl+"&id="+id,
                    success:function (data){
                        if(data.code == 1){
                            alert("保存成功");
                            window.history.back();
                        }
                    }
                })
            }
        })

    })

    var selectArea2 = new MobileSelectArea();
    selectArea2.init({
        position:"bottom",
        trigger:$('#txt_area'),
        value:$('#txt_area').val(),
        data:json3,
        callback:function (scroller,text,value){
            console.log("vals="+value);
            _address.province = text[0];
            _address.city = text[1];
            _address.area = text[2];
            $("#txt_area").val(_address.province+ " "+_address.city+" "+_address.area);
        }
    });

</script>
</body>

</html>